home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -serious- / programming / other / hexy / src / hexy_guicontrol.c < prev    next >
C/C++ Source or Header  |  1999-09-06  |  28KB  |  1,000 lines

  1.  
  2. /*
  3.  * [!BGN - MACHINE GENERATED - DO NOT EDIT THIS HEADER]
  4.  *
  5.  * Program   : Hexy (Binary file viewer/editor for the Amiga.)
  6.  * Version   : 1.6
  7.  * File      : Work:Source/!WIP/HisoftProjects/Hexy/Hexy_guicontrol.c
  8.  * Author    : Andrew Bell
  9.  * Copyright : Copyright © 1998-1999 Andrew Bell (See GNU GPL)
  10.  * Created   : Saturday 28-Feb-98 16:00:00
  11.  * Modified  : Sunday 22-Aug-99 23:31:45
  12.  * Comment   : 
  13.  *
  14.  * (Generated with StampSource 1.2 by Andrew Bell)
  15.  *
  16.  * [!END - MACHINE GENERATED - DO NOT EDIT THIS HEADER]
  17.  *
  18.  */
  19.  
  20. /* Created: Sun/09/Aug/1998 */
  21.  
  22. /*
  23.  *  Hexy, binary file viewer and editor for the Amiga.
  24.  *  Copyright (C) 1999 Andrew Bell
  25.  *
  26.  *  Author's email address: andrew.ab2000@bigfoot.com
  27.  *
  28.  *  This program is free software; you can redistribute it and/or modify
  29.  *  it under the terms of the GNU General Public License as published by
  30.  *  the Free Software Foundation; either version 2 of the License, or
  31.  *  (at your option) any later version.
  32.  *
  33.  *  This program is distributed in the hope that it will be useful,
  34.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  35.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36.  *  GNU General Public License for more details.
  37.  *
  38.  *  You should have received a copy of the GNU General Public License
  39.  *  along with this program; if not, write to the Free Software
  40.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  41.  *
  42.  */
  43.  
  44. /* At one time Hexy's GUI was created with IEditor. Some of the
  45.    IEditor code remains in this file */
  46.  
  47. #include <Hexy.h>
  48.  
  49. /* Prototypes */
  50.  
  51. Prototype BOOL ViewGUI( void );
  52. Prototype void ClearGUI( void );
  53. Prototype void SwapPort(struct Window *Win, struct MsgPort *NewMP);
  54. Prototype void FlushWindow(struct Window *Win);
  55. Prototype void SetMODE( void );
  56. Prototype void UpdateMODE( void );
  57. Prototype UBYTE *MakeUniqueScrName(UBYTE *FmtString, UBYTE *PubScreenNameBuf);
  58. Prototype void PrintStatus( register __a0 UBYTE *String, register __a1 APTR Fmt);
  59. Prototype void SetVDragBar(struct VCtrl *CurVC);
  60. Prototype void DoError(BOOL UseDOS);
  61. Prototype LONG SetupScreen( void );
  62. Prototype void CloseDownScreen( void );
  63. Prototype LONG OpenJUMPWindow( void );
  64. Prototype void CloseJUMPWindow( void );
  65. Prototype void JUMPRender( void );
  66. Prototype LONG OpenMAINWindow( void );
  67. Prototype void CloseMAINWindow( void );
  68. Prototype void MAINRender( void );
  69. Prototype LONG OpenFINDWindow( void );
  70. Prototype void CloseFINDWindow( void );
  71. Prototype void FINDRender( void );
  72. Prototype LONG OpenHUNKLISTWindow( void );
  73. Prototype LONG CloseHUNKLISTWindow( void );
  74. Prototype void HexyInformation( UBYTE *String, APTR Fmt );
  75. Prototype struct Screen *HexyScreen;
  76. Prototype ULONG ScreenError;
  77. Prototype UBYTE PubScreenNameBuf[];
  78. Prototype struct PubScreenNode *HexyPSN;
  79.  
  80. #define AMTGADS_MAIN      10
  81. #define GD_GVDRAGBAR      0
  82. #define GD_GNEXTL         1
  83. #define GD_GPREVL         2
  84. #define GD_GNEXTP         3
  85. #define GD_GPREVP         4
  86. #define GD_GSEARCH        5
  87. #define GD_GQUIT          6
  88. #define GD_GMODE          7
  89. #define GD_GSTATUS        8
  90. #define GD_GEDIT          9
  91.  
  92. Prototype struct Screen *Scr;
  93.  
  94. struct Screen *Scr = NULL;
  95. struct Screen *HexyScreen = NULL;
  96. ULONG ScreenError = NULL;
  97. UBYTE PubScreenNameBuf[256+4];
  98. struct PubScreenNode *HexyPSN = NULL;
  99. UWORD YOffset = NULL;
  100. UWORD XOffset = NULL;
  101. APTR VisualInfo;
  102. UBYTE *PubScreenName = NULL;
  103.  
  104. Prototype struct Gadget *MAINGList;
  105. Prototype struct Gadget *MAINGadgets[];
  106. Prototype struct Window *MAINWnd;
  107.  
  108. struct Gadget *MAINGList = NULL;
  109. struct Gadget *MAINGadgets[AMTGADS_MAIN];
  110. struct Window *MAINWnd = NULL;
  111.  
  112. struct TextAttr HexyTextAttr =
  113. {
  114.   "topaz.font",
  115.   8,
  116.   FS_NORMAL,
  117.   FPF_ROMFONT
  118. };
  119.  
  120. struct TextFont *HexyTextFont = NULL;
  121.  
  122. BOOL ViewGUI( void )
  123. {
  124.   /*************************************************
  125.    *
  126.    * 
  127.    *
  128.    */
  129.  
  130.   UWORD Gimme3DEmbrossedLook = -1;
  131.  
  132.   if (GUIActive) return(TRUE);
  133.  
  134.   HexyTextFont = OpenFont( (struct TextAttr *) &HexyTextAttr );
  135.  
  136.   if (!HexyTextFont) return FALSE;
  137.  
  138.   PubScreenName = MakeUniqueScrName("HEXY_SCREEN.%lu", (UBYTE *) &PubScreenNameBuf);
  139.  
  140.   /*
  141.   ** use NewScreen structure here
  142.   */
  143.   HexyScreen = (struct Screen *) OpenScreenTags(NULL,
  144.               SA_Left,       0,
  145.               SA_Top,        0,
  146.               SA_Width,      640,
  147.               SA_Height,     256,
  148.               SA_Depth,      2, /* 2 planes = 4 colours */
  149.               SA_Title,      VERS " (" DATE ") screen (Status = PUBLIC)",
  150.               SA_Type,       PUBLICSCREEN,
  151.               SA_DisplayID,  (HIRES_KEY | PAL_MONITOR_ID),
  152.               SA_AutoScroll, TRUE,
  153.               SA_PubName,    PubScreenName,
  154.               SA_Pens,       &Gimme3DEmbrossedLook,
  155.               SA_ErrorCode,  &ScreenError,
  156.               SA_Font,       &HexyTextAttr,
  157.               TAG_DONE);
  158.  
  159.   if (!HexyScreen) return(FALSE);
  160.   PubScreenStatus(HexyScreen, 0);   /* Make screen public */
  161.  
  162.   if (SetupScreen()) return(FALSE);
  163.   if (OpenMAINWindow()) return(FALSE);
  164.  
  165.   VC.VC_RPort = MAINWnd->RPort;
  166.  
  167.   SwapPort(MAINWnd, WinPort);
  168.   SetMODE();
  169.  
  170.   KillAppIcon(); /* Kill AppIcon (If it exists) */
  171.  
  172.   if (VC.VC_FileAddress)  /* If VC contains a file then display it! */
  173.   {
  174.     UpdateView(&VC, NULL);
  175.     SetVDragBar(&VC);
  176.   }
  177.  
  178.   DisplayFileInfos(&VC);
  179.  
  180.   GUIActive = TRUE;
  181.   return(TRUE);
  182. }
  183.  
  184. void ClearGUI( void )
  185. {
  186.   /*************************************************
  187.    *
  188.    * 
  189.    *
  190.    */
  191.  
  192.   if (HexyScreen) PubScreenStatus(HexyScreen, PSNF_PRIVATE);
  193.  
  194.   ClearJumpWindow();
  195.   ClearFindWindow();
  196.   ClearHunkListWindow();
  197.  
  198.   /* Check for visitor windows on the public Hexy screen */
  199.  
  200.   FlushWindow( MAINWnd );
  201.   CloseMAINWindow();
  202.   CloseDownScreen();
  203.  
  204.   if (HexyScreen)
  205.   {
  206.     while (!CloseScreen(HexyScreen))
  207.     {
  208.       struct EasyStruct VisitorES =
  209.       {
  210.         sizeof(struct EasyStruct),
  211.         NULL,
  212.         "Hexy info...",
  213.         "Unable to close Hexy screen!\n%lu (<-- Remember to fix this Andrew) alien windows are present!",
  214.         "Retry"
  215.       };
  216.  
  217.       SetupScreen();
  218.       OpenMAINWindow();
  219.  
  220.       stream[0] = (ULONG) HexyPSN->psn_VisitorCount;
  221.       EasyRequestArgs(MAINWnd, &VisitorES, NULL, &stream);
  222.  
  223.       CloseMAINWindow();
  224.       CloseDownScreen();
  225.     }
  226.     HexyScreen = NULL;
  227.     Scr = NULL;
  228.   }
  229.  
  230.   if (HexyTextFont)
  231.   {
  232.     CloseFont(HexyTextFont);
  233.     HexyTextFont = NULL;
  234.   }
  235.  
  236.   GUIActive = FALSE;
  237. }
  238.  
  239. void SwapPort(struct Window *Win, struct MsgPort *NewMP)
  240. {
  241.   /*************************************************
  242.    *
  243.    * 
  244.    *
  245.    */
  246.  
  247.   ULONG TempIDCMPFlags = Win->IDCMPFlags;
  248.   ModifyIDCMP(Win, NULL);           /* Check result */
  249.   Win->UserPort = NewMP;
  250.   ModifyIDCMP(Win, TempIDCMPFlags);
  251. }
  252.  
  253. void FlushWindow(struct Window *Win)
  254. {
  255.   /*************************************************
  256.    *
  257.    * 
  258.    *
  259.    */
  260.  
  261.   if (!Win) return;
  262.  
  263.   Forbid();
  264.  
  265.   if (Win->UserPort)
  266.   {
  267.     struct IntuiMessage *ThisNode = (struct IntuiMessage *) Win->UserPort->mp_MsgList.lh_Head;
  268.  
  269.     if ( (((ULONG)ThisNode) != ~NULL) && (ThisNode != NULL) )
  270.     {
  271.       do
  272.       {
  273.         if ( ThisNode->IDCMPWindow == Win )
  274.         {
  275.           Remove((struct Node *)ThisNode);
  276.           ReplyMsg((struct Message *)ThisNode);
  277.         }
  278.       }
  279.       while (ThisNode = (struct IntuiMessage *) ((struct Node *)ThisNode)->ln_Succ);
  280.     }
  281.  
  282.     Win->UserPort = NULL;
  283.   }
  284.  
  285.   Permit();
  286. }
  287.  
  288. void SetMODE( void )
  289. {
  290.   /*************************************************
  291.    *
  292.    * 
  293.    *
  294.    */
  295.  
  296.   if (!HexyWBMsg)
  297.   {
  298.     /* From Shell */
  299.  
  300.     /*HexyInformation("Hexy was started from Shell", NULL);*/
  301.  
  302.     if (aa[ARG_ASCII])
  303.     {
  304.       VC.VC_Mode = HEXYMODE_ASCII;
  305.     }
  306.     else
  307.     {
  308.       VC.VC_Mode = HEXYMODE_HEX;
  309.     }
  310.   }
  311.   else
  312.   {
  313.     VC.VC_Mode = HEXYMODE_HEX;
  314.   }
  315.     
  316.   UpdateMODE();
  317. }
  318.  
  319. void UpdateMODE( void )
  320. {
  321.   /*************************************************
  322.    *
  323.    * 
  324.    *
  325.    */
  326.  
  327.   UWORD CY_Active;
  328.  
  329.   if (VC.VC_Mode == HEXYMODE_ASCII)
  330.   {
  331.     CY_Active = HEXYMODE_ASCII;
  332.   }
  333.   else
  334.   {
  335.     CY_Active = HEXYMODE_HEX;
  336.   }
  337.   
  338.   GT_SetGadgetAttrs(MAINGadgets[GD_GMODE], MAINWnd, NULL,
  339.         GTCY_Active, CY_Active,
  340.         TAG_DONE);
  341. }
  342.  
  343. UBYTE *MakeUniqueScrName(UBYTE *FmtString, UBYTE *PubScreenNameBuf)
  344. {
  345.   /*************************************************
  346.    *
  347.    * 
  348.    *
  349.    */
  350.  
  351.   struct List *ScreenList = LockPubScreenList();
  352.   ULONG cnt = NULL;
  353.  
  354.   do
  355.   {
  356.     RawDoFmt(FmtString, &cnt, (void *) &putChProc, PubScreenNameBuf); cnt++;
  357.   }
  358.   while (FindName(ScreenList, PubScreenNameBuf));
  359.  
  360.   UnlockPubScreenList();
  361.   return(PubScreenNameBuf);
  362. }
  363.  
  364. void PrintStatus( register __a0 UBYTE *String, register __a1 APTR Fmt)
  365. {
  366.   /*************************************************
  367.    *
  368.    * 
  369.    *
  370.    */
  371.  
  372.   UBYTE FmtBuf[256+4];
  373.  
  374.   if (!GUIActive) return;
  375.  
  376.   RawDoFmt(String, Fmt, (void *) &putChProc, &FmtBuf);
  377.   GT_SetGadgetAttrs(MAINGadgets[GD_GSTATUS], MAINWnd, NULL,
  378.             GTTX_Text, &FmtBuf,
  379.             TAG_DONE);
  380. }
  381.  
  382. void SetVDragBar(struct VCtrl *CurVC)
  383. {
  384.   /*************************************************
  385.    *
  386.    * 
  387.    *
  388.    */
  389.  
  390.   ULONG XByte;
  391.  
  392.   if (CurVC->VC_Mode == HEXYMODE_HEX)
  393.   {
  394.     XByte = XAMOUNT_HEX;
  395.   }
  396.   else
  397.   {
  398.     XByte = XAMOUNT_ASCII;
  399.   }
  400.  
  401.   GT_SetGadgetAttrs(MAINGadgets[GD_GVDRAGBAR], MAINWnd, NULL,
  402.         GTSC_Top,     (CurVC->VC_CurrentPoint/XByte),
  403.         GTSC_Total,   (CurVC->VC_FileLength/XByte) + 1,
  404.         GTSC_Visible, YLINES,
  405.         TAG_DONE);
  406. }
  407.  
  408. void DoError(BOOL UseDOS)
  409. {
  410.   /*************************************************
  411.    *
  412.    * 
  413.    *
  414.    */
  415.  
  416.   /* If UseDOS is TRUE then the output goes to Shell */
  417.  
  418.   if (UseDOS)
  419.   {
  420.     PrintFault(IoErr(), "Hexy error ");
  421.   }
  422.   else
  423.   {
  424.     UBYTE TmpErrStrBuf[256+4];
  425.     Fault(IoErr(), "", (UBYTE *) &TmpErrStrBuf, 256);
  426.  
  427.     stream[0] = (ULONG) IoErr();
  428.     stream[1] = (ULONG) &TmpErrStrBuf;
  429.     PrintStatus("Operation failed! DOS: %lu %s", &stream);
  430.   }
  431. }
  432.  
  433. struct TextFont *HexyFont = NULL;
  434.  
  435. LONG SetupScreen( void )
  436. {
  437.   /*************************************************
  438.    *
  439.    * 
  440.    *
  441.    */
  442.  
  443.   if(!( Scr = LockPubScreen( PubScreenName )))
  444.   {
  445.     return( 1L );
  446.   }
  447.  
  448.   YOffset = Scr->WBorTop + Scr->Font->ta_YSize;
  449.   XOffset = Scr->WBorLeft;
  450.  
  451.   if(!( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  452.   {
  453.     return( 1L );
  454.   }
  455.  
  456.   return( 0L );
  457. }
  458.  
  459.  
  460. void CloseDownScreen( void )
  461. {
  462.   /*************************************************
  463.    *
  464.    * 
  465.    *
  466.    */
  467.  
  468.   if( VisualInfo )
  469.   {
  470.     FreeVisualInfo( VisualInfo );
  471.     VisualInfo = NULL;
  472.   }
  473.  
  474.   if( Scr )
  475.   {
  476.     UnlockPubScreen( NULL, Scr );
  477.     Scr = NULL;
  478.   }
  479. }
  480.  
  481. /*************************************************
  482.  *
  483.  * 
  484.  *
  485.  */
  486.  
  487. struct Gadget *FINDGadgets[20+4];
  488. struct Window *FINDWnd = NULL;
  489. struct Gadget *FINDGList = NULL;
  490.  
  491. Prototype struct Gadget *FINDGadgets[];
  492. Prototype struct Window *FINDWnd;
  493. Prototype struct Gadget *FINDGList;
  494.  
  495. LONG OpenFINDWindow( void )
  496. {
  497.   if ( Gad = CreateContext( &FINDGList ) )
  498.   {
  499.     struct NewGadget ng_GD_FGFINDNEXT   = { 129, 56, 85,  13,   "Find Next",     NULL, GD_FGFINDNEXT,   NULL,            VisualInfo, NULL };
  500.     ULONG gt_GD_FGFINDNEXT[]            = { TAG_DONE };
  501.     struct NewGadget ng_GD_FGDONE       = { 340, 56, 85,  13,   "Done",          NULL, GD_FGDONE,       NULL,            VisualInfo, NULL };
  502.     ULONG gt_GD_FGDONE[]                = { TAG_DONE };
  503.     struct NewGadget ng_GD_FGSTRING     = { 78,  7,  343, 12,   "String:",       NULL, GD_FGSTRING,     NULL,            VisualInfo, NULL };
  504.     ULONG gt_GD_FGSTRING[]              = { TAG_DONE };
  505.     struct NewGadget ng_GD_FGIGNORECASE = { 14,  38, 26,  11,   "Ignore case",   NULL, GD_FGIGNORECASE, PLACETEXT_RIGHT, VisualInfo, NULL };
  506.     ULONG gt_GD_FGIGNORECASE[]          = { GA_Disabled, TRUE, TAG_DONE };
  507.     struct NewGadget ng_GD_FGBINSEARCH  = { 153, 38, 26,  11,   "Binary search", NULL, GD_FGBINSEARCH,  PLACETEXT_RIGHT, VisualInfo, NULL };
  508.     ULONG gt_GD_FGBINSEARCH[]           = { GA_Disabled, TRUE, TAG_DONE }; /* Bin search has been disabled because it's too unstable. */
  509.     struct NewGadget ng_GD_FGFINDPREV   = { 14,  56, 85,  13,   "Find Prev",     NULL, GD_FGFINDPREV,   NULL,            VisualInfo, NULL };
  510.     ULONG gt_GD_FGFINDPREV[]            = { TAG_DONE };
  511.     struct NewGadget ng_GD_FGBINRESULT  = { 80,  21, 343, 12,   "Bin:",          NULL, GD_FGBINRESULT,  NULL,            VisualInfo, NULL };
  512.     ULONG gt_GD_FGBINRESULT[]           = { GTTX_CopyText, TRUE, GTTX_Border, TRUE, GTTX_Clipped, TRUE, TAG_DONE };
  513.  
  514.     FINDGadgets[GD_FGFINDNEXT]   = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_FGFINDNEXT,   (struct TagItem *) >_GD_FGFINDNEXT   );
  515.     FINDGadgets[GD_FGDONE]       = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_FGDONE,       (struct TagItem *) >_GD_FGDONE       );
  516.     FINDGadgets[GD_FGSTRING]     = Gad = CreateGadgetA( STRING_KIND,   Gad, &ng_GD_FGSTRING,     (struct TagItem *) >_GD_FGSTRING     );
  517.     FINDGadgets[GD_FGIGNORECASE] = Gad = CreateGadgetA( CHECKBOX_KIND, Gad, &ng_GD_FGIGNORECASE, (struct TagItem *) >_GD_FGIGNORECASE );
  518.     FINDGadgets[GD_FGBINSEARCH]  = Gad = CreateGadgetA( CHECKBOX_KIND, Gad, &ng_GD_FGBINSEARCH,  (struct TagItem *) >_GD_FGBINSEARCH  );
  519.     FINDGadgets[GD_FGFINDPREV]   = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_FGFINDPREV,   (struct TagItem *) >_GD_FGFINDPREV   );
  520.     FINDGadgets[GD_FGBINRESULT]  = Gad = CreateGadgetA( TEXT_KIND,     Gad, &ng_GD_FGBINRESULT,  (struct TagItem *) >_GD_FGBINRESULT  );
  521.  
  522.     if ( Gad )
  523.     {
  524.       FINDWnd = OpenWindowTags( NULL,
  525.         WA_Left,      75,
  526.         WA_Top,       111,
  527.         WA_Width,     441,
  528.         WA_Height,    86,
  529.         WA_MinWidth,  0,
  530.         WA_MaxWidth,  -1,
  531.         WA_MinHeight, 0,
  532.         WA_MaxHeight, -1,
  533.         WA_PubScreen, Scr,
  534.         WA_Title,     "Find...",
  535.         WA_Flags,     ( WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_NEWLOOKMENUS | WFLG_GIMMEZEROZERO ),
  536.         WA_IDCMP,     ( BUTTONIDCMP | CHECKBOXIDCMP | STRINGIDCMP | TEXTIDCMP | IDCMP_REFRESHWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_GADGETUP | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW | IDCMP_VANILLAKEY | IDCMP_MENUHELP | IDCMP_GADGETHELP ),
  537.         WA_Gadgets,   FINDGList,
  538.         TAG_DONE );
  539.  
  540.         if ( FINDWnd )
  541.         {
  542.           FINDRender();
  543.  
  544.           return 0;
  545.         }
  546.         else
  547.         {
  548.           HexyInformation( "Unable to create find window", NULL);
  549.         }
  550.  
  551.     }
  552.     else
  553.     {
  554.       HexyInformation( "Unable to create gadgets for find window", NULL);
  555.       return 1; /* FAIL */
  556.     }
  557.  
  558.   }
  559.   else
  560.   {
  561.     HexyInformation( "Unable to init find window gadget list", NULL);
  562.     return 1; /* FAIL */
  563.   }
  564.  
  565.   return 1;
  566. }
  567.  
  568. void CloseFINDWindow( void )
  569. {
  570.   if ( FINDWnd )
  571.   {
  572.     FlushWindow( FINDWnd );
  573.     CloseWindow( FINDWnd );
  574.     FINDWnd = NULL;
  575.   }
  576.  
  577.   if ( FINDGList )
  578.   {
  579.     FreeGadgets( FINDGList );
  580.     FINDGList = NULL;
  581.   }
  582. }
  583.  
  584. void FINDRender( void )
  585. {
  586.   DrawBevelBox( FINDWnd->RPort, 0, 0, 434, 73,
  587.     GT_VisualInfo, VisualInfo, TAG_DONE );
  588. }
  589.  
  590. /*************************************************
  591.  *
  592.  * 
  593.  *
  594.  */
  595.  
  596. struct Gadget *HUNKLISTGadgets[20+4];
  597. struct Window *HUNKLISTWnd = NULL;
  598. struct Gadget *HUNKLISTGList = NULL;
  599.  
  600. Prototype struct Gadget *HUNKLISTGadgets[];
  601. Prototype struct Window *HUNKLISTWnd;
  602. Prototype struct Gadget *HUNKLISTGList;
  603.  
  604. LONG OpenHUNKLISTWindow( void )
  605. {
  606.   struct Gadget *Gad;
  607.   BOOL Failure = FALSE;
  608.  
  609.   if (Gad = CreateContext( &HUNKLISTGList ))
  610.   {
  611.     /* New gads and tags here */
  612.  
  613.     struct NewGadget ng_GD_HLLV   = {   5,  16, 480, 103, "Offset     Hunk ID       Information                       ", NULL, GD_HLLV, PLACETEXT_ABOVE, VisualInfo, NULL };
  614.     ULONG gt_GD_HLLV[]            = { GTLV_ShowSelected, NULL, TAG_DONE };
  615.     struct NewGadget ng_GD_HLDONE = { 374, 118, 110,  12,  "Done",      NULL, GD_HLDONE, NULL, VisualInfo, NULL };
  616.     ULONG gt_GD_HLDONE[]          = { TAG_DONE };
  617.     struct NewGadget ng_GD_HLGOTO = {   5, 118, 110,  12,  "Goto",      NULL, GD_HLGOTO, NULL, VisualInfo, NULL };
  618.     ULONG gt_GD_HLGOTO[]          = { TAG_DONE };
  619.  
  620.     HUNKLISTGadgets[GD_HLLV]   = Gad = CreateGadgetA( LISTVIEW_KIND, Gad, &ng_GD_HLLV,       (struct TagItem *) >_GD_HLLV   );
  621.     HUNKLISTGadgets[GD_HLDONE] = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_HLDONE,     (struct TagItem *) >_GD_HLDONE );
  622.     HUNKLISTGadgets[GD_HLGOTO] = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_HLGOTO,     (struct TagItem *) >_GD_HLGOTO );
  623.  
  624.     if ( Gad )
  625.     {
  626.       HUNKLISTWnd = OpenWindowTags(NULL,
  627.         WA_Left,      50,
  628.         WA_Top,       66,
  629.         WA_Width,     500,
  630.         WA_Height,    147,
  631.         WA_MinWidth,  0,
  632.         WA_MaxWidth,  -1,
  633.         WA_MinHeight, 0,
  634.         WA_MaxHeight, -1,
  635.         WA_PubScreen, Scr,
  636.         WA_Title,     "Select a hunk to jump to...",
  637.         WA_Flags,     WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_RMBTRAP | WFLG_NOCAREREFRESH | WFLG_NEWLOOKMENUS | WFLG_GIMMEZEROZERO,
  638.         WA_IDCMP,     BUTTONIDCMP | LISTVIEWIDCMP | IDCMP_REFRESHWINDOW | IDCMP_GADGETUP | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY,
  639.         WA_Gadgets,   HUNKLISTGList,
  640.         TAG_DONE );
  641.  
  642.         if ( HUNKLISTWnd )
  643.         {
  644.           return 0;
  645.         }
  646.         else
  647.         {
  648.           HexyInformation( "Unable to create hunk-list window", NULL);
  649.         }
  650.  
  651.     }
  652.     else
  653.     {
  654.       HexyInformation( "Unable to create gadgets for hunk-list window", NULL);
  655.       return 1; /* FAIL */
  656.     }
  657.  
  658.   }
  659.   else
  660.   {
  661.     HexyInformation( "Unable to init hunk-list window gadget list", NULL);
  662.     return 1; /* FAIL */
  663.   }
  664.  
  665.   return 1;
  666. }
  667.  
  668. LONG CloseHUNKLISTWindow( void )
  669. {
  670.   if ( HUNKLISTWnd )
  671.   {
  672.     FlushWindow( HUNKLISTWnd );
  673.     CloseWindow( HUNKLISTWnd );
  674.     HUNKLISTWnd = NULL;
  675.   }
  676.  
  677.   if ( HUNKLISTGList )
  678.   {
  679.     FreeGadgets( HUNKLISTGList );
  680.     HUNKLISTGList = NULL;
  681.   }
  682.  
  683.   return 0;
  684. }
  685.  
  686. /*************************************************
  687.  *
  688.  * 
  689.  *
  690.  */
  691.  
  692. Prototype struct Gadget *JUMPGadgets[];
  693. Prototype struct Window *JUMPWnd;
  694.  
  695. struct Gadget *JUMPGadgets[20+4];
  696. struct Window *JUMPWnd = NULL;
  697. struct Gadget *JUMPGList = NULL;
  698.  
  699. LONG OpenJUMPWindow( void ) /* BUG: Jump has a hidden string gadget ! */
  700. {
  701.   struct Gadget *Gad;
  702.   BOOL Failure = FALSE;
  703.  
  704.   if (Gad = CreateContext( &JUMPGList ))
  705.   {
  706.     struct NewGadget ng_GD_JGSTRING = { 10, 20, 177, 14, "Jump to offset", NULL, GD_JGSTRING, PLACETEXT_LEFT, VisualInfo, NULL };
  707.     ULONG gt_GD_JGSTRING[] = { TAG_DONE };
  708.  
  709.     struct NewGadget ng_GD_JGDONE =   { 189, 20, 58, 14, "Done",           NULL, GD_JGDONE, PLACETEXT_IN, VisualInfo, NULL };
  710.     ULONG gt_GD_JGDONE[] = { TAG_DONE };
  711.  
  712.     JUMPGadgets[GD_JGSTRING]   = Gad = CreateGadgetA(STRING_KIND,     Gad, &ng_GD_JGSTRING,   (struct TagItem *) >_GD_JGSTRING );
  713.     JUMPGadgets[GD_JGDONE]     = Gad = CreateGadgetA(BUTTON_KIND,     Gad, &ng_GD_JGDONE,     (struct TagItem *) >_GD_JGDONE );
  714.  
  715.     if ( Gad )
  716.     {
  717.       JUMPWnd = OpenWindowTags(NULL,
  718.         WA_Left,         76,
  719.         WA_Top,          62,
  720.         WA_Width,        262,
  721.         WA_Height,       44,
  722.         WA_MinWidth,     0,
  723.         WA_MaxWidth,     -1,
  724.         WA_MinHeight,    0,
  725.         WA_MaxHeight,    -1,
  726.         WA_PubScreen,    Scr,
  727.         WA_Title,        "Jump to offset",
  728.         WA_Flags,        (WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_NEWLOOKMENUS),
  729.         WA_IDCMP,        (BUTTONIDCMP | STRINGIDCMP | IDCMP_REFRESHWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_GADGETUP | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW | IDCMP_VANILLAKEY | IDCMP_MENUHELP | IDCMP_GADGETHELP ),
  730.         WA_Gadgets,      JUMPGList,
  731.         TAG_DONE );
  732.  
  733.         if ( JUMPWnd )
  734.         {
  735.           JUMPRender();
  736.  
  737.           return 0;
  738.         }
  739.         else
  740.         {
  741.           HexyInformation( "Unable to create jump window", NULL);
  742.         }
  743.  
  744.     }
  745.     else
  746.     {
  747.       HexyInformation( "Unable to create gadgets for jump window", NULL);
  748.       return 1; /* FAIL */
  749.     }
  750.  
  751.   }
  752.   else
  753.   {
  754.     HexyInformation( "Unable to init jump window gadget list", NULL);
  755.     return 1; /* FAIL */
  756.   }
  757.  
  758.   return 0; /* OK */
  759. }
  760.  
  761. void CloseJUMPWindow( void )
  762. {
  763.   if ( JUMPWnd )
  764.   {
  765.     FlushWindow( JUMPWnd );
  766.     CloseWindow( JUMPWnd );
  767.     JUMPWnd = NULL;
  768.   }
  769.  
  770.   if ( JUMPGList )
  771.   {
  772.     FreeGadgets( JUMPGList );
  773.     JUMPGList = NULL;
  774.   }
  775. }
  776.  
  777. void JUMPRender( void )
  778. {
  779.   DrawBevelBox( JUMPWnd->RPort, 0 + XOffset, 1 + YOffset, 254, 31,
  780.     GT_VisualInfo, VisualInfo, TAG_DONE );
  781. }
  782.  
  783. UBYTE *Array0[] =
  784. {
  785.   "HEX",
  786.   "ASCII",
  787.   NULL
  788. };
  789.  
  790. /*************************************************
  791.  *
  792.  * 
  793.  *
  794.  */
  795.  
  796. Prototype struct Menu *MAINMenus;
  797.  
  798. struct Menu *MAINMenus;
  799.  
  800. LONG OpenMAINWindow( void )
  801. {
  802.   struct Gadget *Gad;
  803.  
  804.   if (Gad = CreateContext( &MAINGList ))
  805.   {
  806.     struct NewGadget ng_GD_GVDRAGBAR = { 608, 4, 17, 199, NULL, NULL, GD_GVDRAGBAR, NULL, VisualInfo, NULL };
  807.     ULONG gt_GD_GVDRAGBAR[]          = { GTSC_Arrows, 8, PGA_Freedom, LORIENT_VERT, GA_Immediate, TRUE, GA_RelVerify, TRUE, TAG_DONE };
  808.     struct NewGadget ng_GD_GNEXTL    = { 9, 218, 81, 12, "Line+", NULL, GD_GNEXTL, PLACETEXT_IN, VisualInfo, NULL };
  809.     ULONG gt_GD_GNEXTL[]             = { TAG_DONE };
  810.     struct NewGadget ng_GD_GPREVL    = { 97, 218, 81, 12, "Line-", NULL, GD_GPREVL, PLACETEXT_IN, VisualInfo, NULL };
  811.     ULONG gt_GD_GPREVL[]             = { TAG_DONE };
  812.     struct NewGadget ng_GD_GNEXTP    = { 185, 218, 81, 12, "Page+", NULL, GD_GNEXTP, PLACETEXT_IN, VisualInfo, NULL };
  813.     ULONG gt_GD_GNEXTP[]             = { TAG_DONE };
  814.     struct NewGadget ng_GD_GPREVP    = { 273, 218, 81, 12, "Page-", NULL, GD_GPREVP, PLACETEXT_IN, VisualInfo, NULL };
  815.     ULONG gt_GD_GPREVP[]             = { TAG_DONE };
  816.     struct NewGadget ng_GD_GSEARCH   = { 361, 218, 81, 12, "Find", NULL, GD_GSEARCH, PLACETEXT_IN, VisualInfo, NULL };
  817.     ULONG gt_GD_GSEARCH[]            = { TAG_DONE };
  818.     struct NewGadget ng_GD_GQUIT     = { 542, 218, 81, 12, "Quit", NULL, GD_GQUIT, PLACETEXT_IN, VisualInfo, NULL };
  819.     ULONG gt_GD_GQUIT[]              = { TAG_DONE };
  820.     struct NewGadget ng_GD_GMODE     = { 449, 218, 81, 12, NULL, NULL, GD_GMODE, NULL, VisualInfo, NULL };
  821.     ULONG gt_GD_GMODE[]              = { GTCY_Labels, (ULONG) &Array0, GTCY_Active, HEXYMODE_HEX, TAG_DONE };
  822.     struct NewGadget ng_GD_GSTATUS   = { 71, 204, 481, 12, "Status", NULL, GD_GSTATUS, PLACETEXT_LEFT, VisualInfo, NULL };
  823.     ULONG gt_GD_GSTATUS[]            = { GTTX_Text, (ULONG) "Welcome to Hexy!", GTTX_CopyText, TRUE, GTTX_Border, TRUE, GTTX_Clipped, TRUE, TAG_DONE };
  824.     struct NewGadget ng_GD_GEDIT     = { 597, 204, 26, 11, "Edit", NULL, GD_GEDIT, NULL, VisualInfo, NULL };
  825.     ULONG gt_GD_GEDIT[]              = { TAG_DONE };
  826.  
  827.     /*
  828.      *
  829.      * Create the gadgets for the main window
  830.      *
  831.      */
  832.      
  833.     MAINGadgets[GD_GVDRAGBAR] = Gad = CreateGadgetA( SCROLLER_KIND, Gad, &ng_GD_GVDRAGBAR, (struct TagItem *) >_GD_GVDRAGBAR );
  834.     MAINGadgets[GD_GNEXTL]    = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_GNEXTL,    (struct TagItem *) >_GD_GNEXTL    );
  835.     MAINGadgets[GD_GPREVL]    = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_GPREVL,    (struct TagItem *) >_GD_GPREVL    );
  836.     MAINGadgets[GD_GNEXTP]    = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_GNEXTP,    (struct TagItem *) >_GD_GNEXTP    );
  837.     MAINGadgets[GD_GPREVP]    = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_GPREVP,    (struct TagItem *) >_GD_GPREVP    );
  838.     MAINGadgets[GD_GSEARCH]   = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_GSEARCH,   (struct TagItem *) >_GD_GSEARCH   );
  839.     MAINGadgets[GD_GQUIT]     = Gad = CreateGadgetA( BUTTON_KIND,   Gad, &ng_GD_GQUIT,     (struct TagItem *) >_GD_GQUIT     );
  840.     MAINGadgets[GD_GMODE]     = Gad = CreateGadgetA( CYCLE_KIND,    Gad, &ng_GD_GMODE,     (struct TagItem *) >_GD_GMODE     );
  841.     MAINGadgets[GD_GSTATUS]   = Gad = CreateGadgetA( TEXT_KIND,     Gad, &ng_GD_GSTATUS,   (struct TagItem *) >_GD_GSTATUS   );
  842.     MAINGadgets[GD_GEDIT]     = Gad = CreateGadgetA( CHECKBOX_KIND, Gad, &ng_GD_GEDIT,     (struct TagItem *) >_GD_GEDIT     );
  843.  
  844.     if (Gad)
  845.     {
  846.       struct NewMenu MAINNewMenu[] =
  847.       {
  848.         /*
  849.          *
  850.          * Project menu
  851.          *
  852.          */
  853.  
  854.         NM_TITLE, "Project",                  NULL,  NULL, 0L,  0L,
  855.         NM_ITEM,  "Load file...",             "l",   NULL, 0L,  0L,
  856.         NM_ITEM,  NM_BARLABEL,                NULL,  NULL, 0L,  0L,
  857.         NM_ITEM,  "Save file...",             "s",   NULL, 0L,  0L,
  858.         NM_ITEM,  "Split save file...",       NULL,  NULL, 0L,  0L,
  859.         NM_ITEM,  NM_BARLABEL,                NULL,  NULL, 0L,  0L,
  860.         NM_ITEM,  "Iconify",                  NULL,  NULL, 0L,  0L,
  861.         NM_ITEM,  NM_BARLABEL,                NULL,  NULL, 0L,  0L,
  862.         NM_ITEM,  "About Hexy...",            "a",   NULL, 0L,  0L,
  863.         NM_ITEM,  "Quit Hexy",                "q",   NULL, 0L,  0L,
  864.  
  865.         /*
  866.          *
  867.          * Control menu
  868.          *
  869.          */
  870.  
  871.         NM_TITLE, "Control",                  NULL,  NULL, 0L,  0L,
  872.         NM_ITEM,  "Jump to offset",           "j",   NULL, 0L,  0L,
  873.         NM_ITEM,  "Find ASCII/Bin string...", "f",   NULL, 0L,  0L,
  874.         NM_ITEM,  "Find hunk/segment",        "h",   NULL, 0L,  0L,
  875.  
  876.         NM_END,    NULL,                      NULL,  0,    0L,  0L
  877.       };
  878.  
  879.       if(MAINMenus = CreateMenus( (struct NewMenu *) &MAINNewMenu, TAG_END ))
  880.       {
  881.         register BOOL layoutres = LayoutMenus(MAINMenus, VisualInfo,
  882.             /*GTMN_TextAttr, NULL,*/
  883.             GTMN_NewLookMenus, TRUE,
  884.             TAG_DONE);
  885.  
  886.         if ( layoutres )
  887.         {
  888.           MAINWnd = OpenWindowTags(NULL,
  889.  
  890.             WA_Left,          0,
  891.             WA_Top,           11,
  892.             WA_Width,         640,
  893.             WA_Height,        245,
  894.             WA_MinWidth,      0,
  895.             WA_MaxWidth,      -1,
  896.             WA_MinHeight,     0,
  897.             WA_MaxHeight,     -1,
  898.             WA_PubScreen,     HexyScreen,
  899.  
  900.             WA_Title,         "Main Hexy window",
  901.             WA_Flags,         WFLG_CLOSEGADGET | WFLG_BACKDROP | WFLG_ACTIVATE | WFLG_NEWLOOKMENUS | WFLG_GIMMEZEROZERO,
  902.             WA_IDCMP,         BUTTONIDCMP | CHECKBOXIDCMP | CYCLEIDCMP | SCROLLERIDCMP | TEXTIDCMP | IDCMP_REFRESHWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_GADGETDOWN | IDCMP_GADGETUP | IDCMP_MENUPICK | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW | IDCMP_VANILLAKEY | IDCMP_INTUITICKS | IDCMP_MENUHELP | IDCMP_GADGETHELP,
  903.             WA_ScreenTitle,   "Hexy screen is active",
  904.             WA_AutoAdjust,    FALSE,
  905.             WA_Gadgets,       MAINGList,
  906.  
  907.             TAG_DONE);
  908.  
  909.           if ( MAINWnd )
  910.           {
  911.             SetFont(MAINWnd->RPort, HexyTextFont);
  912.             
  913.             MAINRender();
  914.             GT_RefreshWindow(MAINWnd, NULL);
  915.             SetMenuStrip(MAINWnd, MAINMenus);
  916.             return 0;
  917.           }
  918.           else
  919.           {
  920.             HexyInformation( "Unable to open main window", NULL );
  921.             return 1;
  922.           }
  923.         }
  924.         else
  925.         {
  926.           HexyInformation( "Unable to layout menus for main window", NULL );
  927.           return 1;
  928.         }
  929.       }
  930.       else
  931.       {
  932.         HexyInformation( "Unable to create menus for main window", NULL );
  933.         return 1;
  934.       }
  935.     }
  936.     else
  937.     {
  938.       HexyInformation( "Unable to create gadgets for main window", NULL );
  939.       return 1;
  940.     }
  941.   } /* CreateContext() */
  942.   else
  943.   {
  944.     HexyInformation( "Unable to create gadgets for main window", NULL );
  945.     return 1;
  946.   }
  947. }
  948.  
  949. void CloseMAINWindow( void )
  950. {
  951.     if ( MAINWnd )
  952.     {
  953.       ClearMenuStrip( MAINWnd );
  954.       CloseWindow( MAINWnd ); MAINWnd = NULL;
  955.     }
  956.  
  957.     if (MAINGList)
  958.     {
  959.       FreeGadgets( MAINGList ); MAINGList = NULL;
  960.     }
  961.  
  962.     if (MAINMenus)
  963.     {
  964.       FreeMenus( MAINMenus ); MAINMenus = NULL;
  965.     }
  966. }
  967.  
  968. void MAINRender( void )
  969. {
  970.   DrawBevelBox( MAINWnd->RPort, 7, 217, 618, 14,  GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  971.   DrawBevelBox( MAINWnd->RPort, 5, 4,   603, 199, GT_VisualInfo, VisualInfo, TAG_DONE );
  972.   DrawBevelBox( MAINWnd->RPort, 0, 0,   632, 232, GT_VisualInfo, VisualInfo, TAG_DONE );
  973. }
  974.  
  975. /*************************************************
  976.  *
  977.  * 
  978.  *
  979.  */
  980.  
  981. void HexyInformation( UBYTE *String, APTR Fmt )
  982. {
  983.   struct EasyStruct HexyInfoES =
  984.   {
  985.     sizeof(struct EasyStruct),
  986.     NULL,
  987.     "Hexy information...",
  988.     String,
  989.     "Understood"
  990.   };
  991.   EasyRequestArgs(MAINWnd, &HexyInfoES, NULL, Fmt);
  992. }
  993.  
  994. /*************************************************
  995.  *
  996.  * 
  997.  *
  998.  */
  999.  
  1000.